home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / jpegagasrc11.lha / jpegagasrc / jpegaga / display.c next >
Encoding:
C/C++ Source or Header  |  1994-10-05  |  6.6 KB  |  262 lines

  1. /* Screen display routines              */
  2. /* written by Günther Röhrich           */
  3. /* this source is Public Domain         */
  4.  
  5. /* this works only with OS 3.0 or higher */
  6.  
  7. /* last change: 5-Oct-1994 */
  8.  
  9. #define INTUI_V36_NAMES_ONLY
  10.  
  11. #include <exec/types.h>
  12. #include <intuition/intuition.h>
  13. #include <intuition/screens.h>
  14. #include <graphics/modeid.h>
  15.  
  16.  
  17. #ifndef __GNUC__
  18. #include <pragmas/intuition_pragmas.h>
  19. #include <pragmas/graphics_pragmas.h>
  20. #include <pragmas/exec_pragmas.h>
  21. #include <clib/intuition_protos.h>
  22. #include <clib/graphics_protos.h>
  23. #include <clib/exec_protos.h>
  24. #else
  25. #include <inline/graphics.h>  
  26. #include <inline/intuition.h> 
  27. #include <inline/exec.h>
  28. #endif
  29.  
  30. #define HAM8 1
  31.  
  32.  
  33. struct IntuitionBase *IntuitionBase = NULL;
  34. struct GfxBase *GfxBase = NULL;
  35. extern int VGAenable; /* indicates if user wants to have VGA mode */
  36. extern int SUPER72enable; /* indicates if user wants to have SUPER72 mode */
  37. extern void error_exit(const char *msgtext);
  38. struct Screen *my_screen = NULL;
  39. struct Window *my_window = NULL;
  40. struct RastPort temprp; /* a copy of the screen's RastPort */
  41. int Drow = 0; 
  42.  
  43.  
  44.  
  45. void CloseDisplay(void);
  46.  
  47. /* Initialize the display, colors will be set later */
  48.  
  49. int InitDisplay(int cols, int rows, ULONG Mode, int NumPlanes)
  50. {
  51.   ULONG Depth, DisplayID;
  52.   ULONG NoSUPER72;
  53.  
  54.   if(!(IntuitionBase = OpenLibrary((UBYTE *)"intuition.library", 39)))
  55.    error_exit("Can't open intuition.library V39 or higher");
  56.  
  57.   if(!(GfxBase = OpenLibrary((UBYTE *)"graphics.library",39)))
  58.    error_exit("Can't open graphics.library V39 or higher");
  59.  
  60.   
  61.   /* Calculate a DisplayID */
  62.   /* this should be done better... */
  63.  
  64.   /* check if SUPER72 mode is available */
  65.  
  66.   NoSUPER72 = ModeNotAvailable(SUPER72_MONITOR_ID | SUPERHAMLACE_KEY);
  67.  
  68.  
  69.   if(VGAenable)
  70.   {
  71.     if(Mode == HAM8)
  72.     {
  73.       if(cols > 780 && !NoSUPER72 && SUPER72enable) DisplayID = SUPER72_MONITOR_ID | SUPERHAMLACE_KEY;
  74.       else
  75.       if(cols > 370 || rows > 260)
  76.         DisplayID = VGAPRODUCTHAM_KEY;
  77.       else
  78.         DisplayID = VGALORESHAMDBL_KEY;
  79.     }
  80.     else
  81.     {
  82.       if(cols > 780 && !NoSUPER72 && SUPER72enable) DisplayID = SUPER72_MONITOR_ID | SUPERLACE_KEY;
  83.       else
  84.       if(cols > 370 || rows >260) 
  85.         DisplayID = VGAPRODUCT_KEY;
  86.       else
  87.         DisplayID = VGALORESDBL_KEY;        
  88.     }
  89.   }
  90.   else
  91.   {  
  92.     if(Mode == HAM8)
  93.     {
  94.       if(cols > 370 || rows > 260)
  95.         DisplayID = HIRESHAMLACE_KEY;
  96.       else
  97.         DisplayID = HAM_KEY;
  98.     }
  99.     else
  100.     {
  101.       if(cols > 370 || rows >260) 
  102.         DisplayID = HIRESLACE_KEY;
  103.       else
  104.         DisplayID = LORES_KEY; 
  105.     }   
  106.   }
  107.  
  108.   if(Mode == HAM8) Depth = 8;
  109.     else Depth = NumPlanes;
  110.  
  111.   my_screen = OpenScreenTags(NULL, SA_Width,     (ULONG)cols,
  112.                                    SA_Height,    (ULONG)rows,
  113.                                    SA_Depth,     (ULONG)Depth,
  114.                                    SA_DisplayID, (ULONG)DisplayID,
  115.                                    SA_Type,      (ULONG)CUSTOMSCREEN,
  116.                                    SA_Quiet,     (ULONG)TRUE,
  117.                                    SA_AutoScroll,(ULONG)TRUE,
  118.                                    SA_Overscan,  (ULONG)OSCAN_STANDARD,
  119.                                    TAG_DONE);
  120.  
  121.   if(my_screen == NULL)  return 0;
  122.     
  123.   /* open a dummy window to allow autoscroll feature      */
  124.   
  125.   my_window = OpenWindowTags(NULL, WA_Left,         (ULONG)0,
  126.                                    WA_Top,          (ULONG)0,
  127.                                    WA_Width,        (ULONG)cols,
  128.                                    WA_Height,       (ULONG)rows,
  129.                                    WA_CustomScreen, my_screen,
  130.                                    WA_NoCareRefresh,(ULONG)TRUE,
  131.                                    WA_Borderless,   (ULONG)TRUE,
  132.                                    WA_Backdrop,     (ULONG)TRUE,
  133.                                    WA_RMBTrap,      (ULONG)TRUE, /* disable screen menu drawing */
  134.                                    WA_IDCMP,        (ULONG)IDCMP_MOUSEBUTTONS,
  135.                                    WA_Activate,     (ULONG)TRUE,
  136.                                    WA_BusyPointer,  (ULONG)TRUE, /* V39 only! */
  137.                                    TAG_DONE);
  138.  
  139.   if(my_window == NULL) return 0;
  140.  
  141.   /* initialize temprp for use with WritePixelLine8() */
  142.  
  143.   CopyMem(&my_screen->RastPort, &temprp, sizeof(struct RastPort));
  144.   temprp.Layer = NULL;
  145.   /* V39 function */
  146.   temprp.BitMap = AllocBitMap(cols, 1, my_screen->RastPort.BitMap->Depth, 0, my_screen->RastPort.BitMap);
  147.  
  148.   if(temprp.BitMap == NULL) return 0;
  149.  
  150.   return 1; /* success */  
  151. }
  152.  
  153.  
  154. /* Set a color... */
  155.  
  156. void SetDisplayColor(int ColorNumber, UBYTE r, UBYTE g, UBYTE b)
  157. {
  158.   if(my_screen)
  159.     /* V39 function */
  160.     SetRGB32(&my_screen->ViewPort, (ULONG)ColorNumber, (ULONG)r << 24,
  161.                                                        (ULONG)g << 24,
  162.                                                        (ULONG)b << 24);
  163. }
  164.  
  165.  
  166. /* Close the display */
  167.  
  168. void CloseDisplay(void)
  169. {
  170.   if(my_screen) ScreenToBack(my_screen);
  171.  
  172.   if(temprp.BitMap)
  173.   {
  174.     /* V39 function */
  175.     FreeBitMap(temprp.BitMap);
  176.     temprp.BitMap = NULL;
  177.   }
  178.   if(my_window)
  179.   {
  180.     CloseWindow(my_window);
  181.     my_window = NULL;
  182.   }
  183.   if(my_screen)
  184.   {
  185.     CloseScreen(my_screen);
  186.     my_screen = NULL;
  187.   }
  188.   if(IntuitionBase)
  189.   {
  190.    CloseLibrary(IntuitionBase);
  191.    IntuitionBase = NULL;
  192.   }
  193.   if(GfxBase)
  194.   {
  195.     CloseLibrary(GfxBase);
  196.     GfxBase = NULL;
  197.   }
  198. }
  199.  
  200.  
  201. /* display a line of chunky pixel graphics... */
  202.  
  203.  
  204. void DisplayRow(char *array, int cols)
  205. {
  206.   if(my_screen)
  207.     WritePixelLine8(&my_screen->RastPort, 0, Drow++, cols, array, &temprp);
  208. }
  209.  
  210.  
  211. /* check for a right mouse button press */
  212.  
  213. int CheckButton(void)
  214. {
  215.   struct IntuiMessage *msg;
  216.   int Button = 0;
  217.  
  218.   if(my_window)
  219.   {
  220.     while(msg = (struct IntuiMessage *)GetMsg(my_window->UserPort))
  221.     {
  222.       if(msg->Class == IDCMP_MOUSEBUTTONS)
  223.         if(msg->Code == MENUDOWN)
  224.           Button = 1; 
  225.       ReplyMsg((struct Message *)msg);
  226.       if(Button) break;
  227.     }
  228.   }
  229.   return Button;
  230. }
  231.        
  232. /* final wait after the picture is finished */
  233.  
  234. void FinalWait(void)
  235. {
  236.   struct IntuiMessage *msg;
  237.   int Button = 0;
  238.   struct TagItem WinPointerSet[] = { {WA_Pointer, NULL}, {TAG_DONE, NULL} };
  239.  
  240.   /* set the normal pointer */
  241.   /* V39 function */
  242.  
  243.   /* SetWindowPointer(my_window, WA_Pointer, NULL, TAG_DONE); */
  244.   SetWindowPointerA(my_window, WinPointerSet);
  245.   
  246.   if(my_window)
  247.   {
  248.     while(!Button)
  249.     {
  250.       Wait(1L<<my_window->UserPort->mp_SigBit);
  251.       while(msg = (struct IntuiMessage *)GetMsg(my_window->UserPort))
  252.       {
  253.         if(msg->Class == IDCMP_MOUSEBUTTONS)
  254.           if(msg->Code == MENUDOWN) Button = 1; 
  255.         ReplyMsg((struct Message *)msg);
  256.         if(Button) break;
  257.       }
  258.     }
  259.   }
  260. }
  261.       
  262.